// import Cookies from 'js-cookie'
import types from '@/store/mutation-types';

import { getDownloadList } from '@/services/api/global';
//todo 管理后台获取的全局信息
const global = {
  state: {
    downloadList: [],
    downloadVisible: false, //是否展示下载文件列表
  },
  mutations: {
    // [types.TOGGLE_DEVICE]: (state, device) => {
    //   state.device = device
    // },
    [types.GET_DOWNLOAD_LIST]: (state, list) => {
      state.downloadList = list;
    },
    [types.DOWNLOAD_LIST_VISIBLE]: (state, flag) => {
      state.downloadVisible = flag;
    },
  },
  actions: {
    // [types.GET_GLOBAL_ARGUMENTS]({ commit }) {
    //   commit(types.TOGGLE_SIDEBAR)
    // },
    async [types.GET_DOWNLOAD_LIST]({ commit, dispatch }) {
      //轮循下载列表
      getDownloadList().then(([result, data]) => {
        if (!result) return;
        commit(types.GET_DOWNLOAD_LIST, data);
      });
      setTimeout(() => dispatch(types.GET_DOWNLOAD_LIST), 15000);
    },
  },
};

export default global;
